//
//  AyDiscoverHeaderView.m
//  xWeibo
//
//  Created by alvis mac on 11/5/15.
//  Copyright © 2015 alvis. All rights reserved.
//

#import "AyDiscoverHeaderView.h"
#import "AyDiscoverGridView.h"
#import "UIImageExtend.h"
#import "AyDefine.h"

@interface  AyDiscoverHeaderView()
@property (weak, nonatomic) UIImageView *topImageView;
@property (weak, nonatomic) AyDiscoverGridView *gridView;
@end


@implementation AyDiscoverHeaderView

+ (instancetype)headerView
{
    return [[self alloc] init];
}

- (instancetype)initWithFrame:(CGRect)frame{
    
        frame.size.height = 180;
        self = [super initWithFrame:frame];
        if (self) {
            // 1.头部图片
            UIImageView *topImageView = [[UIImageView alloc] init];
            topImageView.image = [UIImage imageWithName:@"square_ad"];
            [self addSubview:topImageView];
            self.topImageView = topImageView;
            
            // 2.中间格子内容
            AyDiscoverGridView *gridView = [AyDiscoverGridView gridView];
            gridView.gridData = @[@"世界杯", @"英语退出高考", @"深圳暴雨", @"晚安"];
            [self addSubview:gridView];
            self.gridView = gridView;
        }
        return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    // 1.头部图片
    CGFloat topX = IWSettingTableBorder + 2;
    CGFloat topY = IWSettingCellMargin;
    CGFloat topW = self.frame.size.width - 2 * topX;
    CGFloat topH = self.topImageView.image.size.height;
    self.topImageView.frame = CGRectMake(topX, topY, topW, topH);
    
    // 2.格子
    CGFloat gridX = IWSettingTableBorder;
    CGFloat gridY = CGRectGetMaxY(self.topImageView.frame) + IWSettingCellMargin;
    CGFloat gridW = self.frame.size.width - 2 * gridX;
    CGFloat gridH = self.frame.size.height - gridY - IWSettingCellMargin;
    self.gridView.frame = CGRectMake(gridX, gridY, gridW, gridH);
}
@end
